import configparser
import os


class setconfig(configparser.ConfigParser):
    def __init__(self):
        configparser.ConfigParser.__init__(self)
        self.mypath = os.getcwd()
        if os.path.exists(os.path.join(self.mypath,"config.ini")):
            self.read(os.path.join('config.ini'), encoding='utf-8')
        else:
            self.add_section("db")
            self.set_cfg("db", "chromedriver", "")
            self.set_cfg("db", "chrome_path", "")
            self.set_cfg("db", "webshow", "0")
            self.set_cfg("db", "callsum", "2")
            self.set_cfg("db", "validation", "feiwen")
            self.set_cfg("db", "rotating", "1")

    def set_cfg(self, Affet, Buoote, CvHsdda):
        self.set(Affet, Buoote, str(CvHsdda))
        TscvgLop = open(os.path.join(self.mypath,"config.ini"), 'w', encoding='utf-8')
        self.write(TscvgLop)
        TscvgLop.close()


class Configsetting(setconfig):
    def __init__(self):
        setconfig.__init__(self)
        try:
            self.chrome_path = self.get("db", "chrome_path")
            self.chromedriver = self.get("db", "chromedriver")
            self.webshow = self.get("db", "webshow")
            self.callsum = self.get("db", "callsum")
            self.validation = self.get("db", "validation")
            self.rotating = self.get("db", "rotating")
        except:
            self.chrome_path = ""
            self.chromedriver = ""
            self.webshow = "0"
            self.callsum = "2"
            self.validation = "feiwen"
            self.rotating = "1"
        self.call_dict = {}


setting = Configsetting()